
//持续发送请求，保持工号的签入状态
function regWorkHeart()
{
	var cmd = { command:'heart', workNo:global_agentInfo.workNo};
	
	// TODO 发送心跳消息，同时接受语音数据
	var command = JSON.stringify(cmd);
	$.ajax({
		url:"chatMessageAction_queryMessage.action",
		async:false,
		type:"POST",
		data:{"command": cmd,"AppID":global_agentInfo.appId,"id": global_agentInfo.id,"workNo":global_agentInfo.workNo,"status":global_agentInfo.status},
		dataType:'json',
		success:function(message)
		{
			if(message.command != "none")
			{
				onAgentEvent(message);
			}
		},
		error:function()
		{
			//alert("error");
		}
	});
	var temId = setTimeout("regWorkHeart()", 500);
	
	return temId;
}

/**
* 通过回调函数分发服务端返回的事件
* event 跟随事件返回的数据
*/		
function onAgentEvent(event)
{
	var cmd = event.command;
	if(cmd == "none")
	{
		return;
	}
	
	var mediaType = event.mediaType;
	if("undefined" == typeof mediaType)
	{
		return;
	}
	// 语音 voice、邮件 Mail、短信 SMS、微信 WeiXin、微博 WeiBo、在线客服 Chat、视频 Video、传真 Fax
	mediaType = mediaType.toUpperCase();
	switch(mediaType)
	{
	case "VOICE":
		setTimeout(function(){
			Voice(event);
		}, 0);
		break;
	case "MAIL":
		setTimeout(function(){
			Mail(event);
		}, 0);
		break;
	case "SMS":
		setTimeout(function(){
			SMS(event);
		}, 0);
		break;
	case "WEIXIN":
		setTimeout(function(){
			global_agentInfo.weiXinAgent.DispatchEvent(event);
		}, 0);
		break;
	case "WEIBO":
		setTimeout(function(){
			WeiBo(event);
		}, 0);
		break;
	case "CHAT":
		setTimeout(function(){
			global_agentInfo.webAgent.DispatchEvent(event);
		}, 0);
		break;
	case "FAX":
		setTimeout(function(){
			Fax(event);
		}, 0);
		break;
	default :
		showWarningInfo("no deal the mediaType:  " + mediaType);
		break;
	}
}

